using System.Collections.Generic;
using System.Data;
using MallInteractiveMap.ClientDataHandler;
using MallInteractiveMap.Common;
using MallInteractiveMap.DTO;
using MallInteractiveMap.Language;

namespace MallInteractiveMap.CMSWebClient.Presenter
{
    public class MallPresenter
    {
        public MallPresenter()
        {
        }
        public List<DTOMall> GetMalls()
        {
            string error = string.Empty;
            List<DTOMall> mall = ClientData.GetMall(new QueryParamList(), ref error);
            if (!string.IsNullOrEmpty(error))
            {

            }
            return mall;
        }
        public List<DTOMall> GetMalls(int Id)
        {
            string error = string.Empty;
            QueryParamList param = new QueryParamList();
            param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32, ParamValue = Id });
            List<DTOMall> mall = ClientData.GetMall(param, ref error);
            if (!string.IsNullOrEmpty(error))
            {

            }
            return mall;
        }
        public bool SetDataMall(DTOMall oMall)
        {
            QueryParamList param = new QueryParamList();
            if (!oMall.IsNew)
                param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32, ParamValue = oMall.Id });
            else
            {
                param.Add(new QueryParamObj() { ParamName = "LanguageType", DBType = DbType.Int32, ParamValue = LanguageLoader.CurrentLanguageType });
            }
            param.Add(new QueryParamObj() { ParamName = "Name", DBType = DbType.String, ParamValue = oMall.Name });
            param.Add(new QueryParamObj() { ParamName = "Logo", DBType = DbType.Binary, ParamValue = oMall.Logo });
            param.Add(new QueryParamObj() { ParamName = "Address", DBType = DbType.String, ParamValue = oMall.Address });
            param.Add(new QueryParamObj() { ParamName = "Telephone", DBType = DbType.String, ParamValue = oMall.Telephone });
            param.Add(new QueryParamObj() { ParamName = "Email", DBType = DbType.String, ParamValue = oMall.Email });
            param.Add(new QueryParamObj() { ParamName = "ContactPerson", DBType = DbType.String, ParamValue = oMall.ContactPerson });
            param.Add(new QueryParamObj() { ParamName = "Description", DBType = DbType.String, ParamValue = oMall.Description });
            param.Add(new QueryParamObj() { ParamName = "LastUpdated", DBType = DbType.DateTime, ParamValue = oMall.LastUpdated });
            param.Add(new QueryParamObj() { ParamName = "FileName", DBType = DbType.String, ParamValue = oMall.FileName });
            param.Add(new QueryParamObj() { ParamName = "FileType", DBType = DbType.String, ParamValue = oMall.FileType });

            string error = string.Empty;
            string spName = oMall.IsNew ? "INSERTMall " : "UPDATEMall";
            bool isSuccess = ClientData.SetData(param, spName, ref error);
            return string.IsNullOrEmpty(error) & isSuccess;
        }
        public bool SetDataMall(int Id)
        {
            string error = string.Empty;
            QueryParamList param = new QueryParamList();
            param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32, ParamValue = Id });
            bool isSuccess = ClientData.SetData(param, "DELETEMall", ref error);
            return string.IsNullOrEmpty(error) & isSuccess;
        }
    }
}
